<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工程决算管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-label{width: 100px; height: 20px;}
        .layui-form-select{width: 190px;}
        #gonghuoshijian{ width: 100%;}
        .addUser input{width: 86%;}
        .layui-form-select{width: 100%!important;}
        .layui-form-select input{width: 100%;}
        .layui-form-item{padding-left: 0;}
        .layui-form-item .layui-input-inline{width: 73%!important;}
        .masksx{width: 80%!important;}
        .material{display: flex;justify-content: flex-start;padding-left: 15px;padding-right: 77px;margin-bottom: 8px;width: 100%;margin-left: 55px;}
        .material label{float: left;height: 38px;line-height: 38px; display: inline-block;}
        ._mater{width: 49%;margin-left: 30px;}
        .layui-form-select .layui-input{padding-right: 0;}
        ._materwarp{width: 43%;}
        .masksx .forms{padding: 0;}
        .material ._mater_input{width: 10%;}
        ._mater_lab{margin:0 20px;}
        .addTo{background-color: #86B1FC;color: #FFF; width: 10px;height: 10px;display: none}
        .materialone .addTo{display:inline;}
        .mater_btn{margin: 6px 0 0 6px;}
        .material_C{width: 100px;text-align: justify;}
        .material_C:after{content:'';width: 100%;display: inline-block;}
        .materialone .mater_btn{display: none;}
        .layui-form-selectup dl{top: -184px;}
        @media screen and (max-width: 750px){
            .MOVE_queryon .layui-form-item {
                width: 80%;
            }
            .layui-form-item{padding: 0;}
            .MOVE_footer{text-align: right;}
            .MOVE_footer a{color: #FFF;font-size: 20px;line-height: 30px;
                padding: 10px;background-color: #F5A721;height: 100%;position: absolute;right: 0;}
        }
        .layui-form-pane .layui-input-inline{width: 80%;}
        .titles{text-align: center;margin: 0;font-size: 20px;}
        .xuanzhong .layui-input-block{margin-left: 0;}
        /*.beixuan table th{width: 33.333%;}*/
        .masksx{height:70%;}
        .qiye{width: 100%; text-align: center;padding: 10px 5px;}
        .layui-input-inline{width: 300px;}
        .layui-select-title input{width: 100%!important;}
        .xuanzhong{height: 270px; overflow: auto;}
        .xuanzhong thead th{padding: 0;}
        .xuanzhong tbody td{padding: 0;text-align: center;}
        .beixuan thead th{padding: 0;}
        .beixuan tbody td{padding: 0;text-align: center;}
        .beixuan {height: 200px;overflow: auto;margin-top: 20px;}
        .forms{height: 94%;}
        .querens{width: 400px;height: 200px; position: absolute;left: 0;right: 0;top: 0;bottom: 0;border: 1px solid
        #EEE; margin: auto; border-radius: 5px; background-color: #EEE;z-index: 66;display: none;}
        .querens .titles{padding: 0;margin-top: 20px;}
        .querens p{text-align: center;height: 80px;line-height: 80px;}
        .querens ._SUM{text-align: center;}
        /*2018年3月5日16:36:59新增*/
        .beixuan tr{height: 37px;line-height: 37px;}
        .beixuan,.xuanzhong{height: auto;}
        .total{text-align: right;}
        /*用于使页面弹框内部所有tr标签保持统一高度  美化页面*/
    </style>
</head>
<body>
<div class="_PC">
    <a class="dayin" type="button" id="dlink"  style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>
    <form class="layui-form layui-form-pane" id="form_7grid" action="" lay-filter="hetong">
        <div class="formTop layui-row">
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs6">
                <div class="layui-input-inline" style="width: 80%;">
                    <input type="text" name="username" lay-verify="required" placeholder="项目名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs6">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit3" placeholder="请输入创建开始日期">
                    <div class="icons">

                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs6">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit4" placeholder="请输入创建结束日期">
                    <div class="icons">

                    </div>
                </div>
            </div>
            <div>
                <button class="layui-btn" type="button"  onclick="query()">查询</button>
                <button class="layui-btn quanxian" type="button"  onclick="tianjia()" style="background-color: #FF8B34;" QX="api/supply/addJSHistory.do">添加决算记录</button>
            </div>

        </div>
        <table id="demo" lay-filter="test"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-sm quanxian" lay-event="look" QX="api/supply/loadJSHistoryDetails.do">查看</a>

            <!--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="edit">编辑</a>-->
        </script>
        <!--<script type="text/html" id="titleTpl">-->

        <!--<span>{{times(1510635999999)}}</span>-->

        <!--</script>-->
    </form>
    <div id="demo7"></div>

    <div class="mask">
        <div class="masksx">
            <div class="title"><span class="titleL">添加记录决算</span><span class="close">×</span></div>
            <div class="forms">
                <form class="layui-form addUser" method="post" action="">
                    <div class="titles">添加</div>
                    <div class="qiye">
                        <div class="layui-inline">
                            <label class="layui-form-label">工程名称:</label>
                            <div class="layui-input-inline">
                                <select name="modules" lay-verify="required"  lay-filter="qiyeleixing" lay-search="">
                                    <option value="">直接选择或搜索选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="xuanzhong">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>
                                    <div class="layui-form-item" pane="">
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="like1[write]" lay-filter="allChoose" lay-skin="primary" title='' >       <!--checked=""   是否被选中-->
                                        </div>
                                    </div>
                                </th>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>单位</th>
                                <th>采购价</th>
                                <th>数量</th>
                                <th>小计(含税)</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--<tr>-->
                            <!--<td>-->
                            <!--<div class="layui-form-item" pane="">-->
                            <!--<div class="layui-input-block">-->
                            <!--<input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title='' checked="">-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--</td>-->
                            <!--<td>铸铁井盖</td>-->
                            <!--<td>100*200</td>-->
                            <!--<td>3</td>-->
                            <!--<td>3</td>-->
                            <!--<td>3</td>-->
                            <!--<td>3</td>-->
                            <!--</tr>-->
                            </tbody>
                        </table>
                    </div>
                    <p class="total">总记金额：<span class="qian">0</span>(万元)</p>
                    <div class="beixuan">
                        <div class="titles">确认</div>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>单位</th>
                                <th>采购价</th>
                                <th>数量</th>
                                <th>税率</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--<tr>-->
                            <!--<th>铸铁井盖</th>-->
                            <!--<th>100*200</th>-->
                            <!--<th>-->
                            <!--<input type="number" class="inputs" lay-verify="required"/>-->
                            <!--</th>-->
                            <!--</tr>-->
                            </tbody>
                        </table>
                    </div>

                    <div class="_submit" style="text-align: right;">
                        <button class="layui-btn layui-btn-sm layui-btn-disabled tijiao" lay-submit type="button" style="margin-right: 50px;">确定
                        </button>
                    </div>

                </form>

            </div>

        </div>

    </div>
    <div class="querens" style="z-index: 9999">
        <div class="titles">提交确认</div>
        <div class="querensON">
            <p>您确认提交吗?</p>
        </div>

        <div class="_SUM">
            <button class="layui-btn layui-btn-sm tijiaos" lay-submit lay-filter="_subm" style="margin-right: 50px;">确定</button>
            <button class="layui-btn layui-btn-sm quxiao" type="button">取消</button>
        </div>
    </div>


</div>


<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>

    function query() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;
            var pronName=$("[name='username']").val();
            var begintime=$('#test-limit3').val();
            var endtime=$('#test-limit4').val();


            if(!AntiSqlValid(pronName)){
                if(lbq('api/supply/loadJSHistoryList.do')) {

                    API.gongchengjuesuan({
                        'mname': pronName,
                        'begintime': begintime,
                        'endtime': endtime,
                        'p': getCookie('yanzheng')
                    })
                }
            }else {
                layer.msg('请勿输入特殊符号');
            };
        })

    }

    function tianjia() {
        layui.use(['form', 'layedit', 'laydate','table','element','laypage','flow'], function() {
            var form=layui.form;
            $('.xuanzhong tbody').html('');
            $('.beixuan tbody').html('');

            ajaxs('/api/public/loadPriDropDown.do','post',{'type':'c','p':getCookie('yanzheng')},function (data) {
                $('[name="modules"]').val('');
                //清空数据，防止每次叠加
                $('[name="modules"]').empty();
                //console.log(data)
                var datas = data.data;
                for (var i = 0; i < datas.length; i++) {
                    $('[name="modules"]').append('<option value="' + datas[i].cc_UUID + '">' + datas[i].eppName+'('+datas[i].eppStaEnd +')'+ '</option>\n')
                }
                form.render();

            });


            form.on('select(qiyeleixing)', function(data){
                //console.log(data.elem); //得到select原始DOM对象
                //console.log(data.value); //得到被选中的值
                //console.log(data.othis); //得到美化后的DOM对象
                sessionStorage.ccuid=data.value;

                $('.beixuan tbody').html('');
                ajaxs('/api/supply/loadJSHistoryDetails.do','post',{'type':'c','ct_id':data.value,'p':getCookie('yanzheng')},function
                    (data) {
                    //console.log(data);
                    var datas=data.data;


                    $('.xuanzhong tbody').html('');
                    for(var i=0;i<datas.length;i++){
                        if(datas[i].mat_Bit=='根'){
                            datas[i].old_Price=datas[i].old_Price*6;
                        }

                        var nums=datas[i].rm_Num*datas[i].old_Price;            //获取小计金额
                        nums+=nums*(datas[i].mat_Tax/100);
                        nums=parseFloat(nums.toFixed(2));
                        $('.xuanzhong tbody').append('  <tr S_id="'+datas[i].id+'" C_id="'+datas[i].mat_Id+'" J_jia="'+datas[i].old_Price+'" G_gui="'+datas[i].mat_Spec+'" S_num="'+datas[i].rm_Num+'" D_dan="'+datas[i].mat_Bit+'" S_sui="'+datas[i].mat_Tax+'" names="'+datas[i].mat_Name+'" zongjia="'+nums+'">\n' +
                            '                                  <td>  \n' +
                            '                                            <div         class="layui-form-item"   pane="">\n' +
                            '                                    <div class="layui-input-block">\n' +
                            '                                    <input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title=\'\'>\n' +
                            '                                    </div>\n' +
                            '                                    </div>\n' +
                            '                                </td>\n' +
                            '                                <td>'+datas[i].mat_Name+'</td>\n' +
                            '                                <td>'+datas[i].mat_Spec+'</td>\n' +
                            '                                <td>'+datas[i].mat_Bit+'</td>\n' +
                            '                                <td>'+datas[i].old_Price+'</td>\n' +
                            '                                <td>'+datas[i].rm_Num+'</td>\n' +
                            '                                <td>'+nums+'</td>\n' +
                            '                            </tr>');
                        form.render();
                    };
                })
            });
        });
        $('.mask').show();



    }

    layui.use(['form', 'layedit', 'laydate','table','element','laypage','flow'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,laypage=layui.laypage
            ,flow=layui.flow
            ,element=layui.element;
        jiazais();

        laydate.render({
            elem: '#gonghuoshijian' //指定元素
            ,type: 'datetime'
        });

        var zongjia=0;          //用以计算总价

        $(document).on('click','.mater_btn',function () {
            $(this).parent().remove();
        });

        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
            $('.querens').hide();
            $('.qian').html(0);
        });

        $('.quxiao').on('click',function () {
            $('.querens').hide();
        });
        dayintishi('.dayin');


        //日期控件
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });

        //执行渲染
        if(lbq('api/supply/loadJSHistoryList.do')){
            API.gongchengjuesuan({'p':getCookie('yanzheng')});
        };



        //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.layui-btn-normal');     //查询 开始结束时间判断

        //监听全选
        form.on('checkbox(allChoose)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');         //找到tbody下的所有多选框
            child.each(function(index, item){                             //循环每个参数item  每个多选框
                item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
//                $(item).trigger('click');
            });
            form.render('checkbox');        //局部刷新多选框  保持页面操作一致性
            var chuandi=new Object();

            $('.beixuan tbody').html('');

            if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                $('.xuanzhong table tbody tr').each(function () {
                    var _this=$(this);
                    chuandi.names=_this.attr('names');     //材料名
                    chuandi.jia=_this.attr('j_jia');       //价格
                    chuandi.id=_this.attr('s_id');         //原收料单ID
                    chuandi.mat_id=_this.attr('c_id');     //材料ID
                    chuandi.danwei=_this.attr('d_dan');       //单位
                    chuandi.guige=_this.attr('g_gui');        //规格
                    chuandi.num=_this.attr('S_num');          //数量
                    chuandi.shui=_this.attr('S_sui');         //税率
                    chuandi.zong=_this.attr('zongjia');
                    $('.beixuan table tbody').append('<tr s_id="'+chuandi.id+'" c_id="'+chuandi.mat_id+'" j_jia="'+chuandi.jia+'"  d_dan="'+chuandi.danwei+'"  g_gui="'+chuandi.guige+'"  S_num="'+chuandi.num+'" S_sui="'+(chuandi.shui/100)+'">\n' +
                        '                                    <td class="names">'+chuandi.names+'</td>\n' +
                        '                                    <td class="guige">'+chuandi.guige+'</td>\n' +
                        '                                    <td class="guige">'+chuandi.danwei+'</td>\n' +
                        '                                    <td class="guige">'+chuandi.jia+'</td>\n' +
                        '                                    <td class="guige">'+chuandi.num+'</td>\n' +
                        '                                    <td class="guige">'+chuandi.shui+'%'+'</td>\n' +
                        '                                </tr>')

                });
                $('.tijiao').removeClass('layui-btn-disabled').removeAttr('disabled');
                var zongjia=0;
                $('.xuanzhong tbody tr').each(function (k,v) {
                    console.log($(this).children('td').eq(6).text());
                    zongjia+=parseFloat($(this).children('td').eq(6).text());
                });
                console.log(zongjia);
                $('.qian').html(zongjia.toFixed(2));
            }else{                          //否则循环下半部所有的tr删除对应的tr
                $('.beixuan table tbody tr').each(function () {
                    if($(this).attr('id')==chuandi.id){
                        $(this).remove();
                    }
                });
                $('.tijiao').addClass('layui-btn-disabled').attr('disabled','disabled');
                $('.qian').html(0);         //清空页面值


            };
        });
        //监听单个点击多选
        form.on('checkbox(filter)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var _this=data.othis;
            var chuandi=new Object();
            chuandi.names=$(_this).parents('tr').attr('names');     //材料名
            chuandi.jia=$(_this).parents('tr').attr('j_jia');       //价格
            chuandi.id=$(_this).parents('tr').attr('s_id');         //原收料单ID
            chuandi.mat_id=$(_this).parents('tr').attr('c_id');     //材料ID
            chuandi.danwei=_this.parents('tr').attr('d_dan');       //单位
            chuandi.guige=_this.parents('tr').attr('g_gui');        //规格
            chuandi.num=_this.parents('tr').attr('S_num');          //数量
            chuandi.shui=_this.parents('tr').attr('S_sui');         //税率
            chuandi.zong=_this.parents('tr').attr('zongjia');       //总价

            //console.log(chuandi)
            if(data.elem.checked){
                console.log(chuandi.zong)
                zongjia+=parseFloat(chuandi.zong);              //如果当前行的多选按钮被选中那么总价加上当前行的自定义属性的价格
                zongjia=parseFloat(zongjia.toFixed(2));         //总价转换为保存有两位小数的浮点型整数
                $('.qian').html(zongjia.toFixed(2));                       //渲染到页面内部
            }else{
                console.log(chuandi.zong);
                zongjia-=parseFloat(chuandi.zong);              //如果当前行的多选按钮没有被选中 那么总价减去当前行的自定义属性的价格
                zongjia=parseFloat(zongjia.toFixed(2));         //结果转换为保存有两位小数的浮点型整数
                if(zongjia<0){      //判断  如果点击后  结果值小于0 说明计算出错 需要重新排查原因
                    layer.msg('计算信息有误,请联系管理员核查');
                }
                $('.qian').html(zongjia.toFixed(2));
            };

            var as=true;
            var child = $(data.elem).parents('table').find('thead input[type="checkbox"]');         //找到tbody下的所有多选框
            $('.tijiao').removeClass('layui-btn-disabled');     //提交按钮清除禁用类名

            $('tbody [name="like1[write]"]').each(function () {   //循环所有的tbody下的[name="like1[write]"]   //  就是多选按钮
                if(!$(this).is(':checked')){        //如果当前（任一）未被选中  那么 变量as就为false,否则即为真;
                    as=false;
                    return false;
                }else{
                    as=true;
                };
            });
            if(as){                                 //如果变量为真
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
                });
            }else{
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = false                         //所有多选框  选中或取消选中
                });
            }
            form.render();              //刷新页面

//            //console.log($(data.elem).parent(), 'is i======================== parent =')

            if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                $('.beixuan table tbody').append('<tr s_id="'+chuandi.id+'" c_id="'+chuandi.mat_id+'" j_jia="'+chuandi.jia+'"  d_dan="'+chuandi.danwei+'"  g_gui="'+chuandi.guige+'"  S_num="'+chuandi.num+'" S_sui="'+chuandi.shui/100+'">\n' +
                    '                                    <td class="names">'+chuandi.names+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.guige+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.danwei+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.jia+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.num+'</td>\n' +
                    '                                    <td class="guige">'+chuandi.shui+'%'+'</td>\n' +

                    '                                </tr>')

                $('.tijiao').removeClass('layui-btn-disabled').removeAttr('disabled');

            }else{                          //否则循环下半部所有的tr删除对应的tr
                $('.beixuan table tbody tr').each(function () {
                    if($(this).attr('s_id')==chuandi.id){           //如果 当前的tr的自定义属性s_id等于当前的自定义chuandi.id,那么删除这行
                        $(this).remove();
                    };
                });
                if($('.beixuan tbody tr').length==0){               //如果  被选区内没有了tr提交按钮禁用
                    $('.tijiao').addClass('layui-btn-disabled').attr('disabled','disabled');
                };

            };

        });

        var uuids='';       //接受合同id;
        var dizhi='';       //接受合同地址;

        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'shenqing'){ //发货
                //do somehing
                //console.log(obj)
                //通过ajax获取到材料弹框需要的内容，渲染至页面上
                function cailiaotankuang(obj) {
                    ajaxs('/api/supply/loadJSHistoryDetails.do','post',{'type':'c','cc_uuid':obj.data.cc_uuid,'p':getCookie('yanzheng')},function (data) {
                        //console.log(data)
                        var datas=data.data;
                        $('.xuanzhong table tbody').html('');       //清空页面已显示信息
                        $('.beixuan table tbody').html('');         //清空被选区已显示信息
                        for(var i=0;i<datas.length;i++){            //循环拿到的数据
                            $('.xuanzhong table tbody').append('<tr id="'+datas[i].id+'" mat_id="'+datas[i].mat_id+'" idang="'+datas[i].mat_Price+'">\n' +
                                '                                    <th>\n' +
                                '                                        <div class="layui-form-item" pane="">\n' +
                                '                                            <div class="layui-input-block">\n' +
                                '                                                <input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title=\'\'>' +
                                '                                                <input type="hidden" name="rm_Code" lay-filter="filter" lay-skin="primary" value="001">' +
                                '                                            </div>\n' +
                                '                                        </div>\n' +
                                '                                    </th>\n' +
                                '                                    <th>'+datas[i].mat_Name+'</th>\n' +
                                '                                    <th>'+datas[i].mat_Spec+'</th>\n' +
                                '                                    <th>'+datas[i].feed_Num+'</th>\n' +
                                '                                </tr>')

                        };           //循环渲染页面数据
                        form.render();
                    })
                }
                cailiaotankuang(obj);                  //渲染材料弹框
                uuids=obj.data.cc_uuid;
                dizhi=obj.data.f_adr;
                $('.mask').show();
                $('._submit button').text('发货');
            }else if(layEvent==='look'){
                //console.log(obj)
                sessionStorage.ct_Id=obj.data.ct_Id;                        //短期缓存保存ct_Id
                location.href='./gongchengjuesuanDE.html';                  //页面跳转
            };
        });

        $('.tijiao').on('click',function () {                               //提交按钮点击后
            if($('.beixuan tbody tr').length==0){                           //如果被选区的tr的length 等于0说明没有东西终止操作
                layer.msg('请添加材料或合同');
                return;
            }else {
                $(".querens").show();
            }
        });

        form.on('submit(_subm)',function (data) {                           //点击提交按钮时
            Btnon('tijiaos')                                                //禁用提交按钮
            //console.log(data.field)
            var cailiao='';
            if( $('.beixuan tbody tr').length==0){                          //如果被选区内的tr的length等于0 return false终止执行
                layer.msg('请选择原料');
                return false;
            };
            $('.beixuan tbody tr').each(function () {                       //循环被选区所有的tr
                cailiao+=$(this).attr('s_id')+','+$(this).attr('c_id')+','+$(this).attr('j_jia')+','+$(this).attr('g_gui')+','+$(this).attr('S_num')+','+$(this).attr('d_dan')+','+$(this).attr('S_sui')+'|';
            });
            cailiao=cailiao.substr(0,cailiao.length-1);                     //删除变量材料值的最后一位“|”号
            //console.log(cailiao)
            data.field.paramStr=cailiao;                                    //提交参数方式
            data.field.cc_uuid = sessionStorage.ccuid;
            //console.log(data.field)
            data.field.p=getCookie('yanzheng');
            $('.tijiao').addClass('layui-btn-disabled');
            formAlertAjax('/api/supply/addJSHistory.do',data.field,'.tijiaos');
            return false;
        });
        $("[name='feed_Code']").blur(function () {
            //console.log($(this).val()!= $("[name='namespan']").val())
            if($(this).val()== $("[name='namespan']").val()){
                return;
            }
            ajaxs('/api/public/cheName.do','get',{'type':3,'name':$(this).val()},function (data) {
                //console.log(data)
                if(data.code==0){
                    if(data.data=='1'){
                        layer.msg('申请单号已存在 请重新输入');
                        $('.tijiao').attr('disabled','true').addClass('layui-btn-disabled');//禁止提交按钮点击
                    }else{
                        layer.msg('申请单号可用');
                        $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');//禁止提交按钮点击
                    }

                }
            })
        });
        inputs();
        //材料添加
        $('.material_C').click(function () {
            var _dom=$(this).parents('.materialone').html();
            $('.materialone').after('<div class="material">'+_dom+'</div>');

            form.render();
        })



    })

</script>
</body>
</html>